/**
 * Created by lwy on 2017/5/27.
 */

var province;
var city;
var county;
var provinceId;
var cityId;
var countyId;

$(function(){
    //省
    $.ajax({
        url:'/areaC/province.json',
        dataType:'json',
        type:'post',
        data:{

        },
        success:function(data){
            $('.addressBox').html('');
            for(var i=0;i<data.datas.length;i++){
                $('<li id="'+data.datas[i].id+'" onclick="docity(this);">'+data.datas[i].provinceName+'</li>').appendTo($('.addressBox'));
            }
        }
    })
})

//市
function docity(a){
    var areaId = $(a).attr('id');
    province = $(a).html();
    provinceId = areaId;
    $.ajax({
        url:'/areaC/getCity.json',
        dataType:'json',
        type:'post',
        data:{
            provinceId:areaId,
        },
        success:function(data){
            $('.addressBox').html('');
            for(var i=0;i<data.datas.length;i++){
                $('<li id="'+data.datas[i].id+'" onclick="docounty(this);">'+data.datas[i].cityName+'</li>').appendTo($('.addressBox'));
            }
        }
    })
}

//县
function docounty(e){
    var areaId = $(e).attr('id');
    city = $(e).html();
    cityId = areaId;
    $.ajax({
        url:'/areaC/getArea.json',
        dataType:'json',
        type:'post',
        data:{
            cityId:areaId,
        },
        success:function(data){
            $('.addressBox').html('');
            for(var i=0;i<data.datas.length;i++){
                $('<li id="'+data.datas[i].id+'" onclick="doall(this);">'+data.datas[i].areaName+'</li>').appendTo($('.addressBox'));
            }
        }
    })
}

//跳回所在地区
function doall(c){
    county = $(c).html();
    countyId = $(c).attr('id');
    var address = province+city+county;
    var Myaddress = encodeURI(provinceId+"&cityId="+cityId+"&countyId="+countyId+"&Myaddress="+address);
    window.location.href="add_address2.html?provinceId="+Myaddress;

}
